package org.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.demo.entity.MeetingLog;
import org.example.demo.mapper.MeetingLogMapper;
import org.example.demo.service.MeetingLogService;
import org.springframework.stereotype.Service;

/**
 * 会议日志服务实现类
 */
@Service
public class MeetingLogServiceImpl extends ServiceImpl<MeetingLogMapper, MeetingLog> implements MeetingLogService {

    @Override
    public Page<MeetingLog> selectPage(MeetingLog meetingLog, Integer pageNum, Integer pageSize) {
        Page<MeetingLog> page = new Page<>();
        page.setCurrent(pageNum);
        page.setSize(pageSize);

        QueryWrapper<MeetingLog> queryWrapper = new QueryWrapper<>();

        // 构建查询条件
        queryWrapper.lambda()
                .like(meetingLog.getMeetingTheme() != null && !meetingLog.getMeetingTheme().isEmpty(),
                        MeetingLog::getMeetingTheme, meetingLog.getMeetingTheme())
                .eq(meetingLog.getMeetingType() != null,
                        MeetingLog::getMeetingType, meetingLog.getMeetingType())
                .eq(meetingLog.getMeetingStatus() != null,
                        MeetingLog::getMeetingStatus, meetingLog.getMeetingStatus())
                .like(meetingLog.getMeetingPlace() != null && !meetingLog.getMeetingPlace().isEmpty(),
                        MeetingLog::getMeetingPlace, meetingLog.getMeetingPlace())
                .ge(meetingLog.getMeetingDate() != null,
                        MeetingLog::getMeetingDate, meetingLog.getMeetingDate())
                .orderByDesc(MeetingLog::getMeetingDate);

        return this.page(page, queryWrapper);
    }
}